package com.chuangsi.project.admin.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.chuangsi.common.utils.PageUtils;
import com.chuangsi.framework.web.controller.BaseController;
import com.chuangsi.framework.web.domain.ResultObject;
import com.chuangsi.framework.web.page.TableDataInfo;
import com.chuangsi.project.admin.dto.admin.approve.ReqApplyBackDto;
import com.chuangsi.project.admin.dto.admin.order.ReqOrderDetailDto;
import com.chuangsi.project.admin.dto.admin.order.ReqOrderUpdateDto;
import com.chuangsi.project.admin.dto.admin.product.ReqProductDetailDto;
import com.chuangsi.project.admin.dto.app.ReqAppletsOrderPageDto;
import com.chuangsi.project.admin.dto.app.ResAppletsOrderPageDto;
import com.chuangsi.project.admin.dto.app.file.ReqFileIdDto;
import com.chuangsi.project.admin.dto.app.order.OrderIdDto;
import com.chuangsi.project.admin.dto.app.order.ReqSignDto;
import com.chuangsi.project.admin.dto.app.order.ResOrderAppletsDetailDto;
import com.chuangsi.project.admin.dto.app.product.ReqAppProductListDto;
import com.chuangsi.project.admin.dto.app.product.ReqProductHotQueryDto;
import com.chuangsi.project.admin.dto.app.product.ResAppProductDetailDto;
import com.chuangsi.project.admin.dto.app.product.ResAppProductListDto;
import com.chuangsi.project.admin.dto.app.seal.ResAppSealListDto;
import com.chuangsi.project.admin.service.OrderService;
import com.chuangsi.project.admin.service.ProductService;
import com.chuangsi.project.admin.service.SealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wangshengming
 * @date 2023/3/28
 */
@Api(tags = "APP-全流程")
@RestController
@RequestMapping("/userApi/logicApp")
@Slf4j
public class LogicController extends BaseController {

    @Autowired
    private ProductService productService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private SealService sealService;


    @ApiOperation(value = "产品列表",notes = "杨文博")
    @GetMapping("/productHotQuery")
    public TableDataInfo<ResAppProductListDto> pageQuery(ReqProductHotQueryDto req){
        startPage();
        List<ResAppProductListDto> list = productService.pageQuery(req);
        return getDataTable(list);
    }

    @ApiOperation(value = "产品详情",notes = "杨文博")
    @PostMapping("/productDetail")
    public ResultObject<ResAppProductDetailDto> productAppDetail(@RequestBody @Valid ReqProductDetailDto req){
        ResAppProductDetailDto res = productService.productAppDetail(req);
        return ResultObject.ok("查询成功").setData(res);
    }

    @ApiOperation(value = "合同签署",notes = "杨文博")
    @PostMapping("/sign")
    public ResultObject<OrderIdDto> sign(@RequestBody @Valid ReqSignDto req){
        OrderIdDto res = orderService.sign(req);
        return ResultObject.ok("操作成功").setData(res);
    }

    @ApiOperation(value = "订单列表",notes = "杨文博")
    @GetMapping("/orderPageQuery")
    public TableDataInfo<ResAppletsOrderPageDto> orderPageQuery( ReqAppletsOrderPageDto req){
        startPage();
        List<ResAppletsOrderPageDto> data = orderService.orderPageQuery(req);
        return getDataTable(data);
    }

    @ApiOperation(value = "订单详情",notes = "杨文博")
    @PostMapping("/orderDetail")
    public ResultObject<ResOrderAppletsDetailDto> orderDetail(@RequestBody @Valid ReqOrderDetailDto req){
        ResOrderAppletsDetailDto res = orderService.orderDetail(req);
        return ResultObject.ok("查询成功").setData(res);
    }

    @ApiOperation(value = "订单详情--客户",notes = "杨文博")
    @PostMapping("/orderDetailForUser")
    public ResultObject<ResOrderAppletsDetailDto> orderDetailForUser(){
        ResOrderAppletsDetailDto res = orderService.orderDetailForUser();
        return ResultObject.ok("查询成功").setData(res);
    }

    @ApiOperation(value = "申请退保",notes = "杨文博")
    @PostMapping("/applyBack")
    public ResultObject<Void> applyBack(@RequestBody @Valid ReqApplyBackDto req){
        return orderService.applyBack(req)?ResultObject.ok("退保成功"):ResultObject.error("退保失败");
    }

    @ApiOperation(value = "订单编辑（仅图片）",notes = "杨文博")
    @PostMapping("/orderUpdate")
    public ResultObject<Void> orderUpdate(@RequestBody @Valid ReqOrderUpdateDto req){
        return orderService.orderUpdate(req)?ResultObject.ok("编辑成功"):ResultObject.error("编辑失败");
    }

    @ApiOperation(value = "删除附件",notes = "杨文博")
    @PostMapping("/deleteFile")
    public ResultObject<Void> deleteFile(@RequestBody @Valid ReqFileIdDto req){
        return orderService.deleteFile(req.getFileId())?ResultObject.ok("删除成功"):ResultObject.error("删除失败");
    }

    @ApiOperation(value = "获取印章列表",notes = "杨文博")
    @PostMapping("/getSealList")
    public ResultObject<List<ResAppSealListDto>> getSealList(){
        List<ResAppSealListDto> dataList = sealService.getSealList();
        return ResultObject.ok().setData(dataList);
    }






}
